package com.sebiotec.book.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;
import com.sebiotec.book.model.SearchEntrty;
import com.sebiotec.book.model.post.PostSearchBean;
import com.sebiotec.book.net.BookApiHelper;

import java.util.HashMap;



public class UpComingVIewModel extends AndroidViewModel {
    public MyDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyDataCallBack<T> {
        void onDataSuccessCallBack( T t);
        void onDataFailCallBack(T t);
    }

    public UpComingVIewModel(@NonNull Application application) {
        super(application);
    }

   //获取UpComing数据
     public void   getUpComingData(int categoryid,String Filter,int PageIndex,int PageSize,String date,MyDataCallBack<Object> mDataCallBack){


         HashMap<String,Object> map=new HashMap<String, Object>();
         map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
         map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
         map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));
         PostSearchBean bean =new PostSearchBean();
         bean.setCategoryid(categoryid);
         bean.setFilter(Filter);
         bean.setPageIndex(PageIndex);
         bean.setPageSize(PageSize);
         bean.setDate(date);
         BookApiHelper.geRadomApi()
                 .getSearchBookings(map,new BaseHttpUtil<PostSearchBean>().convertVo2Json(bean))
                 .compose(Transformer.<SearchEntrty>switchSchedulers())
                 .subscribe(new CommonObserver<SearchEntrty>() {
                     @Override
                     protected String setTag() {
                         return "UpComing";
                     }

                     @Override
                     protected void onError(String errorMsg) {
                         mDataCallBack.onDataFailCallBack(errorMsg);
                     }

                     @Override
                     protected void onSuccess(SearchEntrty s) {
                         //回调数据
                         mDataCallBack.onDataSuccessCallBack(s);
                     }
                 });


     }





}
